<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/7/22
 * Time: 17:24
 */

namespace app\admin\model\frontend;


use app\admin\model\BaseM;

class LikeM extends BaseM
{

    protected $table = 'tb_like';



    /**
     * 文章喜欢 IP去重
     * @return array|mixed
     */
    public function like(){
        $data=input('post.');
        $realtion_id = $data['realtion_id'];
        $tag = $data['tag'];
        $ip = getIP();
        //如果realtion_id ip 已有则不写入
        $exist = $this->where(['realtion_id'=>$realtion_id,'ip'=>$ip,'tag'=>$tag])->count();
        if ($exist) {
            return op_msg(2,'');
        }else {
            $data['ip'] = $ip;
            $data['created_at'] = time();
            if($this->save($data)){
                return op_success();
            }
        }
        return op_fail();
    }

}